package com.pethub.service.serviceimpl;

import com.pethub.dao.UserDao;
import com.pethub.entity.User;
import com.pethub.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 22017-12-3
 * @author HARDEN
 * @version 1.0
 *
 *除了基本接口外的接口都需要写清注释
 *
 * 对于异常需要处理的可以处理了
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    public Logger logger= Logger.getLogger(UserServiceImpl.class.getName());
    public User load(String id) throws Exception {
        return userDao.load(id);
    }

    public User getByEmail(String email) throws Exception {
        return  userDao.getByEmail(email);
    }

    public User get(String id) throws Exception {
        return userDao.get(id);
    }

    public List<User> findAll(String hql) throws Exception {
        return userDao.findAll(hql);
    }

    public User save(User entity) throws Exception {
        return userDao.save(entity);
    }

    public void saveOrUpdate(User entity) throws Exception {
         userDao.saveOrUpdate(entity);
    }

    public void delete(String id) throws Exception {
        userDao.delete(id);
    }

    public void flush() {
        try {
            userDao.flush();
        } catch (Exception e) {
            logger.error("刷新缓存失败:"+e.getMessage(),e);
        }
    }
}
